<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2020/1/23
  Time: 10:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>考勤管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<script src="../../layui/layui.js" charset="utf-8"></script>
<script src="/js/jquery-3.4.1.js" charset="utf-8"></script>
<script src="/js/common.js" charset="utf-8"></script>
<body style="padding: 10px;background-color: rgb(236,240,245);">
    <h1 style="margin-bottom: 20px;">考勤管理</h1>
    <input id="editOption" value="${editOption}" style="display: none">
    <!-- 功能区+表格 -->
    <div style="background-color: white;">
        <div class="layui-row">
            <!-- 刷新按钮 -->
            <div class="layui-col-xs1" style="padding-left: 10px;padding-top: 10px;">
                <button type="button" class="layui-btn" onclick="location.href='/jsp/attendanceManage/attendanceManage.jsp'">
                    <i class="layui-icon layui-icon-refresh-3" style="font-size: 14px;">刷新</i>
                </button>
            </div>
            <!-- 搜索框 -->
            <div class="layui-form-item layui-col-xs11" style="clear: none !important;margin-bottom: 0 !important;padding-top: 10px;padding-right: 10px;">
                <div style="width: 208px;height: 35px;border: 1px solid #E6E6E6;float: right;padding-left: 5px;">
                    <input id="queryCondition" placeholder="查找..." style="height: inherit;border: 0;"/>
                    <button type="button" class="layui-btn layui-btn-sm layui-bg-cyan" style="position: absolute;height: 35px" onclick="queryAttendance()">
                        <i class="layui-icon layui-icon-search"></i>
                    </button>
                </div>
                <div class="layui-inline" style="float: right">
                    <label class="layui-form-label">查询：</label>
                    <div class="layui-input-inline" style="width: 100px;">
                        <input id="beginDate" placeholder="起始日期" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid">-</div>
                    <div class="layui-input-inline" style="width: 100px;">
                        <input id="endDate" placeholder="结束日期" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
        </div>

        <table class="layui-hide" id="tb_attendance" lay-filter="filter_attendance"></table>
        <!-- 状态框 -->
        <script type="text/html" id="bar_status">
            <a class="layui-btn layui-btn-xs"></a>
        </script>
        <!-- 表格工具列 -->
        <script type="text/html" id="bar_attendanceEdit">
            <a class="layui-btn layui-btn-xs" lay-event="edit">
                <i class="layui-icon layui-icon-edit">修改</i>
            </a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">
                <i class="layui-icon layui-icon-close">删除</i>
            </a>
        </script>
    </div>
</body>
<script>
    $(function () {
        //页面加载完成判断是否是从编辑页面跳转过来的
        isShowSuccessPanel();
    });
    // 表格模块
    layui.use(['table','laydate'], function(){
        var table = layui.table;
        var laydate = layui.laydate;

        laydate.render({
            elem: '#beginDate' //指定元素
        });
        laydate.render({
            elem: '#endDate' //指定元素
        });

        table.render({
            elem:'#tb_attendance',
            url:'/attendanceManage/getAttendanceListByPage.do',
            where:{
                queryCondition:$("#queryCondition").val(),
                beginDate:$("#beginDate").val(),
                endDate:$("#endDate").val()
            },
            title: '考勤列表',
            cols: [[
                {field:'attendance_id', title:'ID', hide: true},
                {field:'real_name', title:'姓名',width:'10%'},
                {field:'user_name', title:'用户名',width:'15%'},
                {field:'dictionary_value', title:'类型',width:'10%'},
                {field:'attendance_time', title:'时间',width:'15%'},
                {field:'attendance_remark', title:'备注'},
                {field:'status_name', title:'状态名', hide: true},
                {field:'theme_skin', title:'状态颜色', hide: true},
                {toolbar: '#bar_status', title:'状态',width:'10%'},
                {toolbar: '#bar_attendanceEdit', title:'操作'}
            ]],
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','refresh'], //自定义分页布局
                groups: 5, //只显示 1 个连续页码
                first: false, //不显示首页
                last: false //不显示尾页
            },
            done: function(res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                var data = res.data;//表格数据数组
                var trList = $("#tb_attendance").next().find(".layui-table-body").find("tr");
                //遍历表格数据，设置状态名称和颜色
                var len = data.length;
                for (i = 0; i < len; i++){

                    var $curr_status = $(trList[i].childNodes[8]).find("a");//当前行的状态的jQuery对象
                    $curr_status.html(data[i].status_name);
                    $curr_status.addClass(data[i].theme_skin);
                }
            }
        });

        //监听行工具事件
        //注：tool 是工具条事件名，filter_role 是 table 原始容器的属性 lay-filter="对应的值"
        table.on('tool(filter_attendance)', function(obj){

            var data = obj.data;//当行数据
            var event = obj.event;//按钮类型
            if(event == 'del'){

                layer.confirm('删除该记录将不能恢复，确定删除吗？', function(index){

                    $.ajax({
                        url:'/attendanceManage/deleteAttendanceById.do',
                        data:{
                            attendance_id:data.attendance_id
                        },
                        dataType:'json',
                        error:function (xmlHttpRequest, textStatus, errorThrown) {//请求失败回调函数

                            layer.msg("删除失败！")
                        }
                    });
                    obj.del();//删除对应行（tr）的DOM结构，并更新缓存
                    layer.close(index);//关闭弹出框
                });
            }else if(event == 'edit'){

                location.href = "/attendanceManage/toAttendanceEditPage.do?attendance_id="+data.attendance_id;
            }
        });
    });

    /**
     * 条件查询考勤列表，重载表格
     */
    function queryAttendance() {
        //重载表格
        layui.table.reload('tb_attendance', {
            url:'/attendanceManage/getAttendanceListByPage.do',
            where:{
                queryCondition:$("#queryCondition").val(),
                beginDate:$("#beginDate").val(),
                endDate:$("#endDate").val()
            }
        });
    }
</script>
</html>
